home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TPLY30.ARJ / DIGRAM.L next >
Text File  |  1991-05-01  |  705b  |  36 lines

  1.  
  2. %{
  3.  
  4. (* Lex demonstration program for the use of the REJECT routine, taken from
  5.    the UNIX manual. This program produces a digram table of the input file
  6.    (counts all pairs of lowercase letters).
  7.    Usage: digram <input-file
  8.    To compile: lex digram
  9.                tpc digram *)
  10.  
  11. uses LexLib;
  12.  
  13. var digram : array ['a'..'z','a'..'z'] of Integer;
  14.  
  15. %}
  16.  
  17. %%
  18.  
  19. [a-z][a-z]    begin
  20.           inc(digram[yytext[1],yytext[2]]);
  21.           reject;
  22.         end;
  23. .        |
  24. \n        ;
  25.  
  26. %%
  27.  
  28. var c,d : char;
  29. begin
  30.   for c := 'a' to 'z' do for d := 'a' to 'z' do digram[c,d] := 0;
  31.   if yylex=0 then
  32.     for c := 'a' to 'z' do for d := 'a' to 'z' do
  33.       if digram[c,d]<>0 then
  34.     writeln(c,d,': ',digram[c,d]);
  35. end.
  36.